﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Persistencia
{
    public class HashTableNCSensitive : System.Collections.Hashtable
    {
        public HashTableNCSensitive(string[] claves, object[] valores)
        {
            int i=0;
            while (i < claves.Length)
            {
                this.Add(claves[i], valores[i]);
                i++;
            }
        }

        public HashTableNCSensitive()
        {
        }

        public override void Add(object key, object value)
        {
            key = key.ToString().ToUpper();
            if (this.Contains(key))
                this[key]=value;
            else
            {
                if (value != null)
                    base.Add(key, value);
                else
                    base.Add(key, null);
            }            

        }

        private bool EsNumerico(object value)
        {
            if (value is IConvertible)
            {
                TypeCode tc = ((IConvertible)value).GetTypeCode();
                if (TypeCode.Char <= tc && tc <= TypeCode.Decimal)
                    return true;
            }
            return false;
        }


        public override bool Contains(object key)
        {
            return base.Contains(key.ToString().ToUpper());
        }

        public override bool ContainsKey(object key)
        {
            return base.ContainsKey(key.ToString().ToUpper());
        }

        public override void Remove(object key)
        {
            base.Remove(key.ToString().ToUpper());
        }

        public override object this[object key]
        {
            get
            {
                return base[key.ToString().ToUpper()];
            }
            set
            {
                base[key.ToString().ToUpper()] = value;
            }
        }

    }
}
